//
//  JBWNavView.m
//  
//
//  Created by 崔志伟 on 2018/7/26.
//

#import "JBWLoginNavView.h"
@interface JBWLoginNavView ()
@property (nonatomic,strong) UILabel  * backTitleLabel ;
@property (nonatomic,copy) void(^backNavBlock)(void) ;
@property(nonatomic,copy)NSString * backTitle ;
@property (nonatomic,strong) UIButton *backBtn ;
@property (nonatomic,strong) UIButton *rightBtn ;
@end
@implementation JBWLoginNavView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self  = [super initWithFrame:frame]) {
        
        self.backBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 40, frame.size.height)];
        [self.backBtn setImage: GetImageNamed(@"sdk_ic_back") forState:UIControlStateNormal];
        [self.backBtn addTarget:self action:@selector(backBtnAction) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.backBtn];
        
        
        self.rightBtn = [[UIButton alloc]initWithFrame:CGRectMake(frame.size.width-40, 0, 40, frame.size.height)];
        [self.rightBtn setImage: GetImageNamed(@"ic_close_style1") forState:UIControlStateNormal];
        [self.rightBtn addTarget:self action:@selector(backBtnAction) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.rightBtn];
        self.isHideRightBtn = YES;
        
        self.backTitleLabel = [[UILabel alloc]initWithFrame:CGRectMake(40, 0, frame.size.width-80, frame.size.height)];
        self.backTitleLabel.textColor = [UIColor whiteColor];
        self.backTitleLabel.font = [UIFont systemFontOfSize:18];
        self.backTitleLabel.textAlignment = NSTextAlignmentLeft;
        [self addSubview:self.backTitleLabel];
        UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, frame.size.height-1, frame.size.width, 1)];
        line.backgroundColor = [UIColor orangeColor];
        [self addSubview:line];
        
        
        
    }
    return self;
}
- (void)setBackTitle:(NSString *)backTitle{
    _backTitle = backTitle;
    self.backTitleLabel.text = _backTitle;
}

- (void)backBtnAction{
    if (self.backNavBlock) {
        self.backNavBlock();
    }
}

- (void)setIsHideRightBtn:(BOOL)isHideRightBtn{
    _isHideRightBtn = isHideRightBtn;
    self.backBtn.hidden = !isHideRightBtn;
    self.rightBtn.hidden = isHideRightBtn;

}

+ (instancetype)showNavViewBackTitle:(NSString *)backTitle backNavBlock:(void(^)(void))backNavBlock{
    
    JBWLoginNavView *navView = [[JBWLoginNavView alloc]initWithFrame:CGRectMake(0, 0, MAIN_BG_VIEW_WIDTH, 48)];
    navView.backTitle = backTitle;
    navView.backNavBlock = backNavBlock;
    return navView;
}









@end
